<?php

//赞美模型
class Digg_model extends Model {
	
	var $options;

	function Digg_model()
	{
		parent::Model();	
		$this->load->database();
		$this->load->model("accounts_model", "am");
		$this->options = array(
			array("id"=>1, "name"=>"谢谢你", "pic"=>"icoThx.gif"),
			array("id"=>2, "name"=>"写得真好", "pic"=>"icoWt.gif"),
			array("id"=>3, "name"=>"你真有趣", "pic"=>"icoFun.gif"),
			array("id"=>4, "name"=>"有品位", "pic"=>"icoTastes.gif"),
			array("id"=>5, "name"=>"你很酷", "pic"=>"icoCool.gif"),
			array("id"=>6, "name"=>"头像好看", "pic"=>"icoHead.gif"),
			array("id"=>7, "name"=>"图片很棒", "pic"=>"icoImg.gif"),
		);
	}
	
	//获取选项
	function options()
	{
		return $this->options;
	}
	
	//获取文章数据
	function get($author)
	{
		//分别获取选项统计
		foreach ($this->options as $k => $option)
		{
			$query = $this->db->get_where("digg", array("author"=>$author, "option"=>$option["id"]));
			$this->options[$k]["count"] = $query->num_rows();
		}
		return $this->options;
	}
	
	//获取文章数据总统计
	function get_count($author)
	{
		$query = $this->db->get_where("digg", array("author"=>$author));
		return $query->num_rows();
	}
	
	//检测是否已经顶过
	function checked($userid, $dataid)
	{
		$query = $this->db->get_where("digg", array("dataid"=>$dataid, "userid"=>$userid));
		if ($query->num_rows()>0) {
			return true;
		}
		return false;
	}
	
	//添加操作
	function set_digg($userid, $author, $dataid, $option)
	{
		//检测登录
		if($userid == 0) return false;
		$data = array(
			"userid" => $userid,
			"author" => $author,
			"dataid" => $dataid,
			"dataid" => $dataid,
			"option" => $option,
			"addtime" => time(),
		);
		$this->db->insert("digg", $data);
		return $this->db->insert_id();
	}
	
}

/* End of file */